package com.baizhi.util;

import com.baomidou.mybatisplus.MybatisSessionFactoryBuilder;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.io.InputStream;

public class MyBatisUtils {

		private static SqlSessionFactory factory;
		static {

			InputStream in = null;
			try {
				in = Resources.getResourceAsStream("mybatis-config.xml");
				factory = new MybatisSessionFactoryBuilder().build(in);
			}catch(Exception e) {
				e.printStackTrace();
				throw new RuntimeException(e);
			}
		}
		

		public static SqlSession openSession() {

			SqlSession sqlSession= factory.openSession();
			return sqlSession;
		}
		

		public static void close(SqlSession sqlSession) {
			sqlSession.close();
		}
	}

